home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-03-05 | 838 b | 31 lines | [TEXT/Help] |
- {Easy memo-functions in help: try (f 100) and more, but you should have memory especially stack !}
-
-
- (define (lookup o t s f)
- (letrec [((lookup t)
- (cond (null? t) (f)
- (let [(pr (0 t))]
- (cond (equal? (0 pr) o) (s pr)
- (lookup (-1 t))))))]
- (lookup t)))
-
- (define (memo p)
- (let [(t ())]
- (lambda a
- (lookup a
- t
- (lambda(pr) (-1 pr))
- (lambda()
- (let [(v (apply p a))]
- (=! t (force (cons (cons a v) t)))
- v))))))
-
- (defmacro (defmemo f | b)
- (cond (cons? f) `(define ,(0 f) (memo (lambda ,(-1 f) ,@b)))
- `(define ,f (memo ,@b))))
-
- (defmemo (f n)
- (cond (<? n 2) 1
- (+ (f (1- n))(f (- n 2)))))
-
-